home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / RTVBE210.ZIP / TESTVESA.C < prev    next >
C/C++ Source or Header  |  1997-01-06  |  4KB  |  139 lines

  1. ;/*************************************************************************
  2. ; *
  3. ; *     File        : TESTVESA.C
  4. ; *
  5. ; *     Description : Test Vesa mode - Initialize mode 640x480x256 in LFB
  6. ; *                   Poke some pixels in Linear Frame buffer
  7. ; *     Copyright (C) 1995,97 RealTech
  8. ; *
  9. ; ************************************************************************/
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <time.h>
  14. #include "_standar.h"
  15. #include "_wdpmi.h"
  16. #include "_dpmi.h"
  17. #include "_vesa.h"
  18. #define    __DEBUG_H
  19. #include "uvbelib.h"
  20. #ifdef __WATCOM__
  21. void waitvr (void);
  22. #pragma aux waitvr =\
  23.     "mov dx,3dah",\
  24.     "wait1:",\
  25.     "in al,dx",\
  26.     "test al,8",\
  27.     "jnz wait1",\
  28.     "wait2:",\
  29.     "in al,dx",\
  30.     "test al,8",\
  31.     "jz wait2",\
  32.     modify [al dx];
  33.  
  34. #endif
  35.  
  36. int mode;
  37.  
  38. void DrawJulia(int DEEP,int MAXITER,float xmin,float xmax,float ymin,float ymax,float a,float b)
  39. {
  40.     float LX = abs(xmax) + abs(xmin), LY = abs(ymax) + abs(ymin),cx,cy,ccy;
  41.     float dLY = LY/(float)modebuf.YResolution;
  42.     float dLX = LX/(float)modebuf.XResolution;
  43.     ushort *video=(ushort*)VESA.Video;
  44.     long delta=(modebuf.BytesPerLine/2)-modebuf.XResolution;
  45.     long y,x,k;
  46.     for (y = 0;y<modebuf.YResolution;y++)
  47.     {
  48.     if (kbhit()) return;
  49.     ccy = ymin + (float)y * dLY;
  50.     for (x = 0;x<modebuf.XResolution; x++,video++)
  51.     {
  52.         float cx2,cy2;
  53.         cx = xmin + (float)x * dLX;
  54.         cy = ccy;
  55.         k = DEEP;
  56.         cx2 = cx * cx;
  57.         cy2 = cy * cy;
  58.         do
  59.         {
  60.         float x1 = cx2 - cy2 - a;
  61.         cy = 2. * cx * cy - b;
  62.         cx = x1;
  63.         k--;
  64.         cx2 = cx*cx;
  65.         cy2 = cy*cy;
  66.         }while ( (cx2 + cy2 <= MAXITER) && (k!=0));
  67.         *video = RGBMask((x<<8)/modebuf.XResolution,(y<<8)/modebuf.YResolution,k<<3);
  68.     }
  69.     video+=delta;
  70.     }
  71.     return;
  72. }
  73.  
  74. void set_vgamode(int a)
  75. {
  76.     __dpmi_regs regs;
  77.     regs.x.ax = a;
  78.     __dpmi_int(0x10,®s);
  79.     return;
  80. }
  81. void error(char *tx,int code)
  82. {
  83.     set_vgamode(0x3);
  84.     fprintf(stderr,"%s code %d\n",tx,code);
  85.     exit(-1);
  86. }
  87. void Disp_VSystem(void)
  88. {
  89.     printf("Realtech VESA Kit v2.10 (C) Copyright Realtech 1996\nhttp://www.worldnet.net/~stedenis\n\n");
  90.     printf("VESA Version :%d.%d\n",vesabuf.VESAVersion>>8,vesabuf.VESAVersion&0xff);
  91.     printf("Vendor       :%s\n",VESA.CardName);
  92.     printf("LFB possible :%d\n",VESA.Linear);
  93.     printf("LFB active   :%d\n",VESA.LFB_actived);
  94.     printf("Selector     :0x%04x\n",VESA.selector);
  95.     printf("Video Ptr    :0x%08x\n",(ulong)VESA.Video);
  96.     printf("BankShift    :%d Granule:%d\n",VESA.bankshift,modebuf.WinGranularity);
  97.     printf("Video Mode %x: %d x %d (scanlength:%d)\n\n",mode,modebuf.XResolution,modebuf.YResolution,modebuf.BytesPerLine);
  98.     return;
  99. }
  100. void main(void)
  101. {
  102.     long t=0;
  103.     UV_install(".\\",0,0);
  104.     printf("VESA 2.00 Kit v2.02\n");
  105.     if (VBE_get_OEM_infos())
  106.     {
  107.     // Search for a 640x480x16bit mode
  108.     mode = VBE_get_mode_by_infos(640,480,16);
  109.     // Set the mode and enable LFB mode
  110.     if (VBE_set_vesa_mode(mode))
  111.     {
  112.         if (VESA.Linear)
  113.         {
  114.         // Draw Directly in VRAM a Julia fractal
  115.         t =clock();
  116.         DrawJulia(32,500,-2.,2,-1,1,.777,.166);
  117.         // Wait for a key
  118.         t=clock()-t;
  119.         getch();
  120.  
  121.         }
  122.         set_vgamode(0x3);
  123.         if (t)
  124.         {
  125.         printf("Delta = %d ms\n",(t*1000L)/CLK_TCK);
  126.         }
  127.     }
  128.     else
  129.     {
  130.        set_vgamode(0x3);
  131.        printf("Cannot initialize mode %x\n",mode);
  132.        getch();
  133.     }
  134.     }
  135.     Disp_VSystem();
  136.     UV_exit();
  137.     return;
  138. }
  139.